﻿/**
 * Copyright (C) 2007 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.thorqq.magictimer.action;

import com.thorqq.magictimer.util.Util;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.BroadcastReceiver;
import android.media.AudioManager;
import android.widget.Toast;


/***
 * Glue class: connects AlarmAlert IntentReceiver to AlarmAlert
 * activity.  Passes through Alarm ID.
 */
// 广播接收器，用来接收定时动作产生的广播事件
public class ActionReceiver extends BroadcastReceiver 
{
    @Override
    public void onReceive(Context context, Intent intent) {
        
        Util.log("onReceive: " + intent.getAction());
                
        //飞行模式状态变化
        if (intent.getAction().equals(Intent.ACTION_AIRPLANE_MODE_CHANGED)) 
        {
            return;
        } 
        //铃音模式变化：铃音、静音、震动
        else if(intent.getAction().equals(AudioManager.RINGER_MODE_CHANGED_ACTION)
                ||intent.getAction().equals(AudioManager.VIBRATE_SETTING_CHANGED_ACTION))
        {
            return;
        }
        //发送短信
        else if (intent.getAction().equals(ActionSendSMS.SMS_SEND_ACTIOIN)) 
        {
          //判断短信是否发送成功   
            switch (getResultCode()) {  
            case Activity.RESULT_OK:  
                Toast.makeText(context, "短信发送成功", Toast.LENGTH_SHORT).show();  
                break;  
            default:  
                Toast.makeText(context, "短信发送失败", Toast.LENGTH_LONG).show();  
                break;  
            }  
            return;
        }        

    }

}

